package com.jeecms.wicool.dao.shops.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.shops.WiPayTypeDao;
import com.jeecms.wicool.entity.shops.PayType;

@Repository
public class WiPayTypeDaoImpl extends HibernateBaseDao<PayType, Integer>
		implements WiPayTypeDao {

	@Override
	protected Class<PayType> getEntityClass() {
		// TODO Auto-generated method stub
		return PayType.class;
	}
	@Override
	public Pagination getPage(int pageNo, int pageSize,CmsUser user) {
			Finder f = Finder.create("select bean from PayType bean where 1=1");
			if(user.getShopId()!=null){
				f.append(" and bean.shopId = :shopId");
				f.setParam("shopId",user.getShopId());
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public PayType findById(Integer id) {
		PayType entity = get(id);
		return entity;
	}
	@Override
	public PayType save(PayType bean) {
		getSession().save(bean);
		return bean;
	}
	@Override
	public PayType deleteById(Integer id) {
		PayType entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	@Override
	public List<PayType> getPayTypeList(Integer shopId) {
		Finder f = Finder.create("select bean from PayType bean where shopId = '"+shopId+"'");
		return find(f);
	}
}